package com.cyp.demo04;


import com.cyp.demo03.Rent;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

//自动生成代理类
public class ProxyInvocationHandler implements InvocationHandler {
//    被代理的接口
    private Object target;

    public void setTarget(Object target) {
        this.target = target;
    }


    public Object getProxy(){
        return  Proxy.newProxyInstance(this.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        log("add");
        Object result = method.invoke(target, args);
        return result;
    }
    public void log(String msg){
        System.out.println("debug使用了"+msg+"方法");
    }
}
